﻿namespace ACCOUNTING.LVY.Business
{
    using ACCOUNTING;
    using Microsoft.VisualBasic.CompilerServices;
    using System;
    using System.Data;
    using System.Windows.Forms;

    public class clsXuatKhoChiTiet
    {
        private double mGiaBan = 0.0;
        private double mGiaBanNT = 0.0;
        private double mGiaVon = 0.0;
        private double mGiaVonNT = 0.0;
        private string mHanSuDung = "";
        private string mKhoa = "";
        private string mKhoaChiTiet = "";
        private string mKhoaDonViTinh = "";
        private string mKhoaHangHoa = "";
        private string mKhoaHoaDon = "";
        private string mKhoaKho = "";
        private string mKhoaPhieuXuat = "";
        private string mKhoaQuayKe = "";
        private string mKhoaTKGiaVon = "";
        private string mKhoaTKHangHoa = "";
        private string mLoai = "";
        private string mNamThang = "";
        private string mNgayBan = "";
        private string mNgayNhap = "";
        private double mQuyCach = 0.0;
        private string mSoLoHang = "";
        private double mSoLuong = 0.0;
        private string mSoSeri = "";
        private double mTienBan = 0.0;
        private double mTienBanNT = 0.0;
        private double mTienChietKhau = 0.0;
        private double mTienChietKhauNT = 0.0;
        private double mTienThue = 0.0;
        private double mTienThueNT = 0.0;
        private double mTienVon = 0.0;
        private double mTienVonNT = 0.0;
        private int mTyLeChietKhau = 0;
        private int mTyLeThue = 0;

        public bool Load(string pKhoa)
        {
            bool flag=false;
            try
            {
                string commandText = "SELECT * FROM ST_XuatKhoChiTiet WHERE Khoa = '" + pKhoa + "'";
                IDataReader dataReader = DBHelper.ExecuteReader(modGeneral.ConnectionString, CommandType.Text, commandText, new IDataParameter[0]);
                if (dataReader.Read())
                {
                    this.mKhoa = Conversions.ToString(modGeneral.GetValue(dataReader, 0, modGeneral.typeOfColumn.GetString));
                    this.mNamThang = Conversions.ToString(modGeneral.GetValue(dataReader, 1, modGeneral.typeOfColumn.GetString));
                    this.mKhoaPhieuXuat = Conversions.ToString(modGeneral.GetValue(dataReader, 2, modGeneral.typeOfColumn.GetString));
                    this.mNgayBan = Conversions.ToString(modGeneral.GetValue(dataReader, 3, modGeneral.typeOfColumn.GetString));
                    this.mKhoaHangHoa = Conversions.ToString(modGeneral.GetValue(dataReader, 4, modGeneral.typeOfColumn.GetString));
                    this.mKhoaKho = Conversions.ToString(modGeneral.GetValue(dataReader, 5, modGeneral.typeOfColumn.GetString));
                    this.mKhoaQuayKe = Conversions.ToString(modGeneral.GetValue(dataReader, 6, modGeneral.typeOfColumn.GetString));
                    this.mSoLoHang = Conversions.ToString(modGeneral.GetValue(dataReader, 7, modGeneral.typeOfColumn.GetString));
                    this.mNgayNhap = Conversions.ToString(modGeneral.GetValue(dataReader, 8, modGeneral.typeOfColumn.GetString));
                    this.mHanSuDung = Conversions.ToString(modGeneral.GetValue(dataReader, 9, modGeneral.typeOfColumn.GetString));
                    this.mSoSeri = Conversions.ToString(modGeneral.GetValue(dataReader, 10, modGeneral.typeOfColumn.GetString));
                    this.mSoLuong = Conversions.ToDouble(modGeneral.GetValue(dataReader, 11, modGeneral.typeOfColumn.GetDecimal));
                    this.mGiaVonNT = Conversions.ToDouble(modGeneral.GetValue(dataReader, 12, modGeneral.typeOfColumn.GetDecimal));
                    this.mGiaVon = Conversions.ToDouble(modGeneral.GetValue(dataReader, 13, modGeneral.typeOfColumn.GetDecimal));
                    this.mTienVonNT = Conversions.ToDouble(modGeneral.GetValue(dataReader, 14, modGeneral.typeOfColumn.GetDecimal));
                    this.mTienVon = Conversions.ToDouble(modGeneral.GetValue(dataReader, 15, modGeneral.typeOfColumn.GetDecimal));
                    this.mGiaBanNT = Conversions.ToDouble(modGeneral.GetValue(dataReader, 0x10, modGeneral.typeOfColumn.GetDecimal));
                    this.mGiaBan = Conversions.ToDouble(modGeneral.GetValue(dataReader, 0x11, modGeneral.typeOfColumn.GetDecimal));
                    this.mTienBanNT = Conversions.ToDouble(modGeneral.GetValue(dataReader, 0x12, modGeneral.typeOfColumn.GetDecimal));
                    this.mTienBan = Conversions.ToDouble(modGeneral.GetValue(dataReader, 0x13, modGeneral.typeOfColumn.GetDecimal));
                    this.mTyLeThue = Conversions.ToInteger(modGeneral.GetValue(dataReader, 20, modGeneral.typeOfColumn.GetInt32));
                    this.mTienThueNT = Conversions.ToDouble(modGeneral.GetValue(dataReader, 0x15, modGeneral.typeOfColumn.GetDecimal));
                    this.mTienThue = Conversions.ToDouble(modGeneral.GetValue(dataReader, 0x16, modGeneral.typeOfColumn.GetDecimal));
                    this.mTyLeChietKhau = Conversions.ToInteger(modGeneral.GetValue(dataReader, 0x17, modGeneral.typeOfColumn.GetInt32));
                    this.mTienChietKhauNT = Conversions.ToDouble(modGeneral.GetValue(dataReader, 0x18, modGeneral.typeOfColumn.GetDecimal));
                    this.mTienChietKhau = Conversions.ToDouble(modGeneral.GetValue(dataReader, 0x19, modGeneral.typeOfColumn.GetDecimal));
                    this.mKhoaDonViTinh = Conversions.ToString(modGeneral.GetValue(dataReader, 0x1a, modGeneral.typeOfColumn.GetString));
                    this.mQuyCach = Conversions.ToDouble(modGeneral.GetValue(dataReader, 0x1b, modGeneral.typeOfColumn.GetDecimal));
                    this.mKhoaTKHangHoa = Conversions.ToString(modGeneral.GetValue(dataReader, 0x1c, modGeneral.typeOfColumn.GetString));
                    this.mKhoaTKGiaVon = Conversions.ToString(modGeneral.GetValue(dataReader, 0x1d, modGeneral.typeOfColumn.GetString));
                    this.mLoai = Conversions.ToString(modGeneral.GetValue(dataReader, 30, modGeneral.typeOfColumn.GetString));
                    this.mKhoaChiTiet = Conversions.ToString(modGeneral.GetValue(dataReader, 0x1f, modGeneral.typeOfColumn.GetString));
                    this.mKhoaHoaDon = Conversions.ToString(modGeneral.GetValue(dataReader, 0x20, modGeneral.typeOfColumn.GetString));
                }
                dataReader.Close();
                flag = true;
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message.ToString());
                flag = false;
                ProjectData.ClearProjectError();
                return flag;
                ProjectData.ClearProjectError();
            }
            return flag;
        }

        public DataTable LoadDetails(string pKhoa)
        {
            DataTable table;
            try
            {
                string commandText = " SELECT CT.Khoa, CT.KhoaKho, K.Ten" + modGeneral.H_LANGUAGE + " as TenKho,  CT.KhoaHangHoa, HH.Ma as MaHang, HH.Ten" + modGeneral.H_LANGUAGE + " as TenHang,  CT.SoLoHang, CT.SoSeri, CT.NgayNhap, CT.HanSuDung, CT.KhoaDonViTinh, DVT.Ten" + modGeneral.H_LANGUAGE + " as DonViTinh,  CT.QuyCach, CT.SoLuong, CT.GiaBanNT, CT.TienBanNT, CT.GiaVonNT, CT.TienVonNT, CT.TyLeChietKhau,  CT.TienChietKhauNT, CT.TyLeThue, CT.TienThueNT, CT.KhoaTKHangHoa, TKHH.SoTaiKhoan as SoTKHangHoa,  CT.KhoaTKGiaVon, TKGV.SoTaiKhoan as SoTKGiaVon  FROM ST_XuatKhoChiTiet CT LEFT JOIN DM_Kho K on CT.KhoaKho = K.Khoa  LEFT JOIN DM_HangHoa HH on CT.KhoaHangHoa = HH.Khoa  LEFT JOIN DM_DonViTinh DVT on CT.KhoaDonViTinh = DVT.Khoa  LEFT JOIN DM_TaiKhoan TKHH on CT.KhoaTKHangHoa = TKHH.Khoa  LEFT JOIN DM_TaiKhoan TKGV on CT.KhoaTKGiaVon = TKGV.Khoa  WHERE CT.Khoa = '" + pKhoa.Trim() + "'";
                table = DBHelper.ExecuteDataset(modGeneral.ConnectionString, CommandType.Text, commandText, new IDataParameter[0]).Tables[0];
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message);
                table = null;
                ProjectData.ClearProjectError();
                return table;
                ProjectData.ClearProjectError();
            }
            return table;
        }

        public bool Save()
        {
            bool flag=false;
            IDataParameter[] commandParameters = new IDataParameter[0x21];
            try
            {
                commandParameters[0] = DBHelper.createParameter("@Khoa", DbType.Int64, ParameterDirection.Input, this.mKhoa);
                commandParameters[1] = DBHelper.createParameter("@NamThang", DbType.Int64, ParameterDirection.Input, this.mNamThang);
                commandParameters[2] = DBHelper.createParameter("@KhoaPhieuXuat", DbType.Int64, ParameterDirection.Input, this.mKhoaPhieuXuat);
                commandParameters[3] = DBHelper.createParameter("@NgayBan", DbType.Int64, ParameterDirection.Input, this.mNgayBan);
                commandParameters[4] = DBHelper.createParameter("@KhoaHangHoa", DbType.Int64, ParameterDirection.Input, this.mKhoaHangHoa);
                commandParameters[5] = DBHelper.createParameter("@KhoaKho", DbType.Int64, ParameterDirection.Input, this.mKhoaKho);
                commandParameters[6] = DBHelper.createParameter("@KhoaQuayKe", DbType.Int64, ParameterDirection.Input, this.mKhoaQuayKe);
                commandParameters[7] = DBHelper.createParameter("@SoLoHang", DbType.Int64, ParameterDirection.Input, this.mSoLoHang);
                commandParameters[8] = DBHelper.createParameter("@NgayNhap", DbType.Int64, ParameterDirection.Input, this.mNgayNhap);
                commandParameters[9] = DBHelper.createParameter("@HanSuDung", DbType.Int64, ParameterDirection.Input, this.mHanSuDung);
                commandParameters[10] = DBHelper.createParameter("@SoSeri", DbType.Int64, ParameterDirection.Input, this.mSoSeri);
                commandParameters[11] = DBHelper.createParameter("@SoLuong", DbType.Date, ParameterDirection.Input, this.mSoLuong);
                commandParameters[12] = DBHelper.createParameter("@GiaVonNT", DbType.Date, ParameterDirection.Input, this.mGiaVonNT);
                commandParameters[13] = DBHelper.createParameter("@GiaVon", DbType.Date, ParameterDirection.Input, this.mGiaVon);
                commandParameters[14] = DBHelper.createParameter("@TienVonNT", DbType.Date, ParameterDirection.Input, this.mTienVonNT);
                commandParameters[15] = DBHelper.createParameter("@TienVon", DbType.Date, ParameterDirection.Input, this.mTienVon);
                commandParameters[0x10] = DBHelper.createParameter("@GiaBanNT", DbType.Date, ParameterDirection.Input, this.mGiaBanNT);
                commandParameters[0x11] = DBHelper.createParameter("@GiaBan", DbType.Date, ParameterDirection.Input, this.mGiaBan);
                commandParameters[0x12] = DBHelper.createParameter("@TienBanNT", DbType.Date, ParameterDirection.Input, this.mTienBanNT);
                commandParameters[0x13] = DBHelper.createParameter("@TienBan", DbType.Date, ParameterDirection.Input, this.mTienBan);
                commandParameters[20] = DBHelper.createParameter("@TyLeThue", DbType.Double, ParameterDirection.Input, this.mTyLeThue);
                commandParameters[0x15] = DBHelper.createParameter("@TienThueNT", DbType.Date, ParameterDirection.Input, this.mTienThueNT);
                commandParameters[0x16] = DBHelper.createParameter("@TienThue", DbType.Date, ParameterDirection.Input, this.mTienThue);
                commandParameters[0x17] = DBHelper.createParameter("@TyLeChietKhau", DbType.Double, ParameterDirection.Input, this.mTyLeChietKhau);
                commandParameters[0x18] = DBHelper.createParameter("@TienChietKhauNT", DbType.Date, ParameterDirection.Input, this.mTienChietKhauNT);
                commandParameters[0x19] = DBHelper.createParameter("@TienChietKhau", DbType.Date, ParameterDirection.Input, this.mTienChietKhau);
                commandParameters[0x1a] = DBHelper.createParameter("@KhoaDonViTinh", DbType.Int64, ParameterDirection.Input, this.mKhoaDonViTinh);
                commandParameters[0x1b] = DBHelper.createParameter("@QuyCach", DbType.Date, ParameterDirection.Input, this.mQuyCach);
                commandParameters[0x1c] = DBHelper.createParameter("@KhoaTKHangHoa", DbType.Int64, ParameterDirection.Input, this.mKhoaTKHangHoa);
                commandParameters[0x1d] = DBHelper.createParameter("@KhoaTKGiaVon", DbType.Int64, ParameterDirection.Input, this.mKhoaTKGiaVon);
                commandParameters[30] = DBHelper.createParameter("@loai", DbType.Int64, ParameterDirection.Input, this.mLoai);
                commandParameters[0x1f] = DBHelper.createParameter("@KhoaChiTiet", DbType.Int64, ParameterDirection.Input, this.mKhoaChiTiet);
                commandParameters[0x20] = DBHelper.createParameter("@KhoaHoaDon", DbType.Int64, ParameterDirection.Input, this.mKhoaHoaDon);
                if (DBHelper.ExecuteNonQuery(modGeneral.ConnectionString, CommandType.StoredProcedure, "ST_sp_XuatKhoChiTiet", commandParameters) > 0)
                {
                    return true;
                }
                flag = false;
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message.ToString());
                flag = false;
                ProjectData.ClearProjectError();
                return flag;
                ProjectData.ClearProjectError();
            }
            return flag;
        }

        public double GiaBan
        {
            get
            {
                return this.mGiaBan;
            }
            set
            {
                this.mGiaBan = value;
            }
        }

        public double GiaBanNT
        {
            get
            {
                return this.mGiaBanNT;
            }
            set
            {
                this.mGiaBanNT = value;
            }
        }

        public double GiaVon
        {
            get
            {
                return this.mGiaVon;
            }
            set
            {
                this.mGiaVon = value;
            }
        }

        public double GiaVonNT
        {
            get
            {
                return this.mGiaVonNT;
            }
            set
            {
                this.mGiaVonNT = value;
            }
        }

        public string HanSuDung
        {
            get
            {
                return this.mHanSuDung;
            }
            set
            {
                this.mHanSuDung = value;
            }
        }

        public string Khoa
        {
            get
            {
                return this.mKhoa;
            }
            set
            {
                this.mKhoa = value;
            }
        }

        public string KhoaChiTiet
        {
            get
            {
                return this.mKhoaChiTiet;
            }
            set
            {
                this.mKhoaChiTiet = value;
            }
        }

        public string KhoaDonViTinh
        {
            get
            {
                return this.mKhoaDonViTinh;
            }
            set
            {
                this.mKhoaDonViTinh = value;
            }
        }

        public string KhoaHangHoa
        {
            get
            {
                return this.mKhoaHangHoa;
            }
            set
            {
                this.mKhoaHangHoa = value;
            }
        }

        public string KhoaHoaDon
        {
            get
            {
                return this.mKhoaHoaDon;
            }
            set
            {
                this.mKhoaHoaDon = value;
            }
        }

        public string KhoaKho
        {
            get
            {
                return this.mKhoaKho;
            }
            set
            {
                this.mKhoaKho = value;
            }
        }

        public string KhoaPhieuXuat
        {
            get
            {
                return this.mKhoaPhieuXuat;
            }
            set
            {
                this.mKhoaPhieuXuat = value;
            }
        }

        public string KhoaQuayKe
        {
            get
            {
                return this.mKhoaQuayKe;
            }
            set
            {
                this.mKhoaQuayKe = value;
            }
        }

        public string KhoaTKGiaVon
        {
            get
            {
                return this.mKhoaTKGiaVon;
            }
            set
            {
                this.mKhoaTKGiaVon = value;
            }
        }

        public string KhoaTKHangHoa
        {
            get
            {
                return this.mKhoaTKHangHoa;
            }
            set
            {
                this.mKhoaTKHangHoa = value;
            }
        }

        public string Loai
        {
            get
            {
                return this.mLoai;
            }
            set
            {
                this.mLoai = value;
            }
        }

        public string NamThang
        {
            get
            {
                return this.mNamThang;
            }
            set
            {
                this.mNamThang = value;
            }
        }

        public string NgayBan
        {
            get
            {
                return this.mNgayBan;
            }
            set
            {
                this.mNgayBan = value;
            }
        }

        public string NgayNhap
        {
            get
            {
                return this.mNgayNhap;
            }
            set
            {
                this.mNgayNhap = value;
            }
        }

        public double QuyCach
        {
            get
            {
                return this.mQuyCach;
            }
            set
            {
                this.mQuyCach = value;
            }
        }

        public string SoLoHang
        {
            get
            {
                return this.mSoLoHang;
            }
            set
            {
                this.mSoLoHang = value;
            }
        }

        public double SoLuong
        {
            get
            {
                return this.mSoLuong;
            }
            set
            {
                this.mSoLuong = value;
            }
        }

        public string SoSeri
        {
            get
            {
                return this.mSoSeri;
            }
            set
            {
                this.mSoSeri = value;
            }
        }

        public double TienBan
        {
            get
            {
                return this.mTienBan;
            }
            set
            {
                this.mTienBan = value;
            }
        }

        public double TienBanNT
        {
            get
            {
                return this.mTienBanNT;
            }
            set
            {
                this.mTienBanNT = value;
            }
        }

        public double TienChietKhau
        {
            get
            {
                return this.mTienChietKhau;
            }
            set
            {
                this.mTienChietKhau = value;
            }
        }

        public double TienChietKhauNT
        {
            get
            {
                return this.mTienChietKhauNT;
            }
            set
            {
                this.mTienChietKhauNT = value;
            }
        }

        public double TienThue
        {
            get
            {
                return this.mTienThue;
            }
            set
            {
                this.mTienThue = value;
            }
        }

        public double TienThueNT
        {
            get
            {
                return this.mTienThueNT;
            }
            set
            {
                this.mTienThueNT = value;
            }
        }

        public double TienVon
        {
            get
            {
                return this.mTienVon;
            }
            set
            {
                this.mTienVon = value;
            }
        }

        public double TienVonNT
        {
            get
            {
                return this.mTienVonNT;
            }
            set
            {
                this.mTienVonNT = value;
            }
        }

        public int TyLeChietKhau
        {
            get
            {
                return this.mTyLeChietKhau;
            }
            set
            {
                this.mTyLeChietKhau = value;
            }
        }

        public int TyLeThue
        {
            get
            {
                return this.mTyLeThue;
            }
            set
            {
                this.mTyLeThue = value;
            }
        }
    }
}

